package cn.secby.wms.controller;

import cn.secby.wms.domain.dto.UserDto;
import cn.secby.wms.domain.vo.Result;
import cn.secby.wms.util.JwtTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/user")
public class UserLoginController {

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody UserDto userDto){
        log.info("登录信息：{}",userDto);

        if(userDto.getUserName().startsWith("error")){
            return Result.builder().code(500).msg("账号或密码错误").build();
        }

        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("userName","zhangsan");
        dataMap.put("account",userDto.getUserName());
        dataMap.put("roles", Arrays.asList("user","leader"));
        dataMap.put("token", JwtTokenUtil.generate(dataMap));
        return Result.builder().code(200).msg("登录成功").data(dataMap).build();
    }
}










